home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
admin
/
accounts
/
acct-1.3
/
acct-1
/
acct-1.3.73
/
kernel_diffs-1.2.0
next >
Wrap
Text File
|
1995-03-07
|
9KB
|
282 lines
diff -ru --new-file linux/arch/i386/kernel/signal.c linux-1.2.0/arch/i386/kernel/signal.c
--- linux/arch/i386/kernel/signal.c Tue Feb 7 11:56:41 1995
+++ linux-1.2.0/arch/i386/kernel/signal.c Wed Mar 8 06:30:26 1995
@@ -208,6 +208,7 @@
/* fall through */
default:
current->signal |= _S(signr & 0x7f);
+ current->flags |= PF_SIGNALED;
do_exit(signr);
}
}
diff -ru --new-file linux/fs/exec.c linux-1.2.0/fs/exec.c
--- linux/fs/exec.c Mon Jan 30 13:08:04 1995
+++ linux-1.2.0/fs/exec.c Wed Mar 8 06:30:26 1995
@@ -212,6 +212,7 @@
if (!file.f_op->write)
goto close_coredump;
has_dumped = 1;
+ current->flags |= PF_DUMPCORE;
strncpy(dump.u_comm, current->comm, sizeof(current->comm));
dump.u_ar0 = (struct pt_regs *)(((unsigned long)(&dump.regs)) - ((unsigned long)(&dump)));
dump.signal = signr;
@@ -775,6 +776,7 @@
current->mm->mmap = NULL;
current->suid = current->euid = current->fsuid = bprm->e_uid;
current->sgid = current->egid = current->fsgid = bprm->e_gid;
+ current->flags &= ~PF_FORKNOEXEC;
if (N_MAGIC(ex) == OMAGIC) {
do_mmap(NULL, 0, ex.a_text+ex.a_data,
PROT_READ|PROT_WRITE|PROT_EXEC,
diff -ru --new-file linux/include/linux/acct.h linux-1.2.0/include/linux/acct.h
--- linux/include/linux/acct.h Thu Jan 1 02:00:00 1970
+++ linux-1.2.0/include/linux/acct.h Wed Mar 8 06:30:26 1995
@@ -0,0 +1,29 @@
+#ifndef __LINUX_ACCT_H
+#define __LINUX_ACCT_H
+
+#define ACCT_COMM 16
+
+struct acct
+{
+ char ac_comm[ACCT_COMM]; /* Accounting command name */
+ time_t ac_utime; /* Accounting user time */
+ time_t ac_stime; /* Accounting system time */
+ time_t ac_etime; /* Accounting elapsed time */
+ time_t ac_btime; /* Beginning time */
+ uid_t ac_uid; /* Accounting user ID */
+ gid_t ac_gid; /* Accounting group ID */
+ dev_t ac_tty; /* controlling tty */
+ char ac_flag; /* Accounting flag */
+ long ac_minflt; /* Accounting minor pagefaults */
+ long ac_majflt; /* Accounting major pagefaults */
+ long ac_exitcode; /* Accounting process exitcode */
+};
+
+#define AFORK 0001 /* has executed fork, but no exec */
+#define ASU 0002 /* used super-user privileges */
+#define ACORE 0004 /* dumped core */
+#define AXSIG 0010 /* killed by a signal */
+
+#define AHZ 100
+
+#endif
diff -ru --new-file linux/include/linux/kernel.h linux-1.2.0/include/linux/kernel.h
--- linux/include/linux/kernel.h Wed Jan 4 21:16:05 1995
+++ linux-1.2.0/include/linux/kernel.h Wed Mar 8 06:30:26 1995
@@ -55,16 +55,9 @@
__attribute__ ((format (printf, 1, 2)));
/*
- * This is defined as a macro, but at some point this might become a
- * real subroutine that sets a flag if it returns true (to do
- * BSD-style accounting where the process is flagged if it uses root
- * privs). The implication of this is that you should do normal
- * permissions checks first, and check suser() last.
- *
* "suser()" checks against the effective user id, while "fsuser()"
* is used for file permission checking and checks against the fsuid..
*/
-#define suser() (current->euid == 0)
#define fsuser() (current->fsuid == 0)
#endif /* __KERNEL__ */
diff -ru --new-file linux/include/linux/sched.h linux-1.2.0/include/linux/sched.h
--- linux/include/linux/sched.h Tue Mar 7 14:38:48 1995
+++ linux-1.2.0/include/linux/sched.h Wed Mar 8 06:30:26 1995
@@ -198,6 +198,10 @@
/* Not implemented yet, only for 486*/
#define PF_PTRACED 0x00000010 /* set if ptrace (0) has been called. */
#define PF_TRACESYS 0x00000020 /* tracing system calls */
+#define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */
+#define PF_SUPERPREV 0x00000100 /* used super-user privileges */
+#define PF_DUMPCORE 0x00000200 /* dumped core */
+#define PF_SIGNALED 0x00000400 /* killed by a signal */
#define PF_STARTING 0x00000100 /* being created */
#define PF_EXITING 0x00000200 /* getting shut down */
@@ -268,6 +272,19 @@
extern int request_irq(unsigned int irq,void (*handler)(int, struct pt_regs *),
unsigned long flags, const char *device);
extern void free_irq(unsigned int irq);
+
+/*
+ * This has now become a routine instead of a macro, it sets a flag if
+ * it returns true (to do BSD-style accounting where the process is flagged
+ * if it uses root privs). The implication of this is that you should do
+ * normal permissions checks first, and check suser() last.
+ */
+extern inline int suser(void)
+{
+ if (current->euid == 0)
+ current->flags |= PF_SUPERPREV;
+ return (current->euid == 0);
+}
extern void copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
extern void flush_thread(void);
diff -ru --new-file linux/kernel/exit.c linux-1.2.0/kernel/exit.c
--- linux/kernel/exit.c Tue Mar 7 14:41:56 1995
+++ linux-1.2.0/kernel/exit.c Wed Mar 8 06:32:40 1995
@@ -18,6 +18,7 @@
#include <asm/segment.h>
extern void sem_exit (void);
+extern void acct_process (long exitcode);
int getrusage(struct task_struct *, int, struct rusage *);
@@ -380,6 +381,7 @@
intr_count = 0;
}
fake_volatile:
+ acct_process(code);
current->flags |= PF_EXITING;
sem_exit();
exit_mmap(current);
diff -ru --new-file linux/kernel/fork.c linux-1.2.0/kernel/fork.c
--- linux/kernel/fork.c Wed Mar 1 13:31:54 1995
+++ linux-1.2.0/kernel/fork.c Wed Mar 8 06:30:26 1995
@@ -188,7 +188,8 @@
p->kernel_stack_page = new_stack;
*(unsigned long *) p->kernel_stack_page = STACK_MAGIC;
p->state = TASK_UNINTERRUPTIBLE;
- p->flags &= ~(PF_PTRACED|PF_TRACESYS);
+ p->flags &= ~(PF_PTRACED|PF_TRACESYS|PF_SUPERPREV);
+ p->flags |= PF_FORKNOEXEC;
p->pid = last_pid;
p->p_pptr = p->p_opptr = current;
p->p_cptr = NULL;
diff -ru --new-file linux/kernel/sys.c linux-1.2.0/kernel/sys.c
--- linux/kernel/sys.c Sun Mar 5 00:16:36 1995
+++ linux-1.2.0/kernel/sys.c Wed Mar 8 06:30:27 1995
@@ -17,6 +17,10 @@
#include <linux/stat.h>
#include <linux/mman.h>
#include <linux/mm.h>
+#include <linux/fcntl.h>
+#include <linux/acct.h>
+#include <linux/tty.h>
+#include <sys/sysmacros.h>
#include <asm/segment.h>
#include <asm/io.h>
@@ -235,10 +239,113 @@
return -EPERM;
return 0;
}
-
-asmlinkage int sys_acct(void)
-{
- return -ENOSYS;
+
+static char acct_active = 0;
+static struct file acct_file;
+
+int acct_process(long exitcode)
+{
+ struct acct ac;
+ unsigned short fs;
+
+ if (acct_active) {
+ strncpy(ac.ac_comm, current->comm, ACCT_COMM);
+ ac.ac_comm[ACCT_COMM] = '\0';
+ ac.ac_utime = current->utime;
+ ac.ac_stime = current->stime;
+ ac.ac_btime = CT_TO_SECS(current->start_time) + (xtime.tv_sec - (jiffies / HZ));
+ ac.ac_etime = CURRENT_TIME - ac.ac_btime;
+ ac.ac_uid = current->uid;
+ ac.ac_gid = current->gid;
+ ac.ac_tty = (current)->tty == NULL ? -1 :
+ makedev (4, current->tty->device);
+ ac.ac_flag = 0;
+ if (current->flags & PF_FORKNOEXEC)
+ ac.ac_flag |= AFORK;
+ if (current->flags & PF_SUPERPREV)
+ ac.ac_flag |= ASU;
+ if (current->flags & PF_DUMPCORE)
+ ac.ac_flag |= ACORE;
+ if (current->flags & PF_SIGNALED)
+ ac.ac_flag |= AXSIG;
+ ac.ac_minflt = current->mm->min_flt;
+ ac.ac_majflt = current->mm->maj_flt;
+ ac.ac_exitcode = exitcode;
+
+ /* Kernel segment override */
+ fs = get_fs();
+ set_fs(KERNEL_DS);
+
+ acct_file.f_op->write(acct_file.f_inode, &acct_file,
+ (char *)&ac, sizeof(struct acct));
+
+ set_fs(fs);
+ }
+ return 0;
+}
+
+asmlinkage int sys_acct(const char *name)
+{
+ struct inode *inode = (struct inode *)0;
+ char *tmp;
+ int error;
+
+ if (!suser())
+ return -EPERM;
+
+ if (name == (char *)0) {
+ if (acct_active) {
+ if (acct_file.f_op->release)
+ acct_file.f_op->release(acct_file.f_inode, &acct_file);
+
+ if (acct_file.f_inode != (struct inode *) 0)
+ iput(acct_file.f_inode);
+
+ acct_active = 0;
+ }
+ return 0;
+ } else {
+ if (!acct_active) {
+
+ if ((error = getname(name, &tmp)) != 0)
+ return (error);
+
+ error = open_namei(tmp, O_RDWR, 0600, &inode, 0);
+ putname(tmp);
+
+ if (error)
+ return (error);
+
+ if (!S_ISREG(inode->i_mode)) {
+ iput(inode);
+ return -EACCES;
+ }
+
+ if (!inode->i_op || !inode->i_op->default_file_ops ||
+ !inode->i_op->default_file_ops->write) {
+ iput(inode);
+ return -EIO;
+ }
+
+ acct_file.f_mode = 3;
+ acct_file.f_flags = 0;
+ acct_file.f_count = 1;
+ acct_file.f_inode = inode;
+ acct_file.f_pos = inode->i_size;
+ acct_file.f_reada = 0;
+ acct_file.f_op = inode->i_op->default_file_ops;
+
+ if (acct_file.f_op->open)
+ if (acct_file.f_op->open(acct_file.f_inode, &acct_file)) {
+ iput(inode);
+ return -EIO;
+ }
+
+ acct_active = 1;
+ return 0;
+ } else
+ return -EBUSY;
+ }
}
asmlinkage int sys_phys(void)